package org.opens.controller;

import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping(value = "/api/cors")
public class CorsController {

    @GetMapping(value = "/{id:\\d+}")
    public Map<String, Object> getRequest(
            @PathVariable(value = "id") Integer id
    ) {
        Map<String, Object> result = new HashMap<>();
        result.put("id", id);
        result.put("method", "get");
        return result;
    }

    @PostMapping(value = "/{id:\\d+}")
    public Map<String, Object> postRequest(
            @PathVariable(value = "id") Integer id
    ) {
        Map<String, Object> result = new HashMap<>();
        result.put("id", id);
        result.put("method", "post");
        return result;
    }

    @PutMapping(value = "/{id:\\d+}")
    public Map<String, Object> putRequest(
            @PathVariable(value = "id") Integer id
    ) {
        Map<String, Object> result = new HashMap<>();
        result.put("id", id);
        result.put("method", "put");
        return result;
    }

    @DeleteMapping(value = "/{id:\\d+}")
    public Map<String, Object> deleteRequest(
            @PathVariable(value = "id") Integer id
    ) {
        Map<String, Object> result = new HashMap<>();
        result.put("id", id);
        result.put("method", "delete");
        return result;
    }

    @PatchMapping(value = "/{id:\\d+}")
    public Map<String, Object> patchRequest(
            @PathVariable(value = "id") Integer id
    ) {
        Map<String, Object> result = new HashMap<>();
        result.put("id", id);
        result.put("method", "patch");
        return result;
    }

}
